package
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.FileFilter;
	import flash.net.FileReference;
	
	import util.SimpleButton;
	
	public class AsToText extends Sprite
	{
		private var fr:FileReference;
		public function AsToText()
		{
			super();
			init();
		}
		
		public function init():void {
			var button:SimpleButton = new SimpleButton("请选择as文件",100);
			button.x = 100;
			button.y = 100;
			this.addChild(button);
			button.addEventListener(MouseEvent.CLICK,onButtonClick);
		}
		
		public function onButtonClick(event:MouseEvent):void {
			var file:FileFilter = new FileFilter(".as","*.as");
			fr = new FileReference();
			fr.addEventListener(Event.SELECT,onSelect);
			fr.browse([file]);
		}
		
		public function onSelect(event:Event):void {
			fr.removeEventListener(Event.SELECT,onSelect);
			fr.addEventListener(Event.COMPLETE,onLoadComplete);
			fr.load();
		}
		
		public function onLoadComplete(event:Event):void {
			fr.removeEventListener(Event.COMPLETE,onLoadComplete);
			var content:String = fr.data.readUTFBytes(fr.data.bytesAvailable);
//			trace(content);
			var tmpReg:RegExp = new RegExp("\\r\\n", "g");
			content = content.replace( tmpReg, "\n" );
			var arrMatch:Array = content.match( new RegExp("Lang\\[\".*\"\\];","g") );
			for each(var el:String in arrMatch) {
//				trace(el);
				var reg:RegExp = new RegExp("\\[\"(.*)\"\\].*\\[(.*)\\]");// /\\[\"(.*)\"\\].*\\[(.*)\\]/;
				var arr:Array = el.match(reg);
				trace(arr.length+"........");
				for each(var e:String in arr) {
					trace(e);
				}
				break;
			}
		}
	}
}
/*******************************************
 * 判断图片
 * 
 * /
/*var t:ByteArray = event.target.data;//获得文件二进制流
var name:String = event.target.name;//获得文件名称
var type:String = event.target.type;//获得后缀名称
var tnum:String = String(t.readUnsignedShort());//读取文件一个16位的整
var results:String;
if(tnum=="65496"){
results="，确实是一个图片。";
}else{
results="，并不是一个图片！";
}
txt.text="您选择的"+name+results;*/	